package com.itboye.hutouben.responsitory;

import com.google.gson.reflect.TypeToken;
import com.itboye.hutouben.bean.HomeMallBean;
import com.itboye.hutouben.bean.WeiXiuBeans;
import com.itboye.hutouben.interfaces.IHomeRadMall;
import com.itboye.hutouben.volley.BaseErrorListener;
import com.itboye.hutouben.volley.BaseNetRepository;
import com.itboye.hutouben.volley.BaseSuccessReqListener;
import com.itboye.hutouben.volley.ByJsonRequest;
import com.itboye.hutouben.volley.ICompleteListener;

import java.lang.reflect.Type;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by itboye on 2016/12/3.
 */

public class HomeMallprinsitory extends BaseNetRepository implements IHomeRadMall<WeiXiuBeans> {

    public static final String Road="By_Repair_add";//道路救援
    public static final String OldDriver="";//老司机
    public static final String ReTItle="By_Repair_rely";

    public HomeMallprinsitory(ICompleteListener iCompleteListener) {
        super(iCompleteListener);
    }

    @Override
    public void onRadRescus(String uid, String mobile,String address,String detail,String vehicle_type, String area,String images,String lng,String lat) {
        Type type = new TypeToken<String>() {
        }.getType();
//        String apiVer = api;
        Map<String, Object> map = new HashMap<>();
        map.put("uid", uid);
        map.put("mobile", mobile);
        map.put("address", address);
        map.put("detail", detail);
        map.put("vehicle_type", vehicle_type);

        map.put("area", area);
        map.put("images",images);
        map.put("lng", lng);
        map.put("lat",lat);

        (new ByJsonRequest.Builder<String>())
                .setTypeVerParamsAndReturnClass(Road, "101", map, type)
                .requestListener(
                        new BaseSuccessReqListener<String>(
                                getListener()))
                .errorListener(new BaseErrorListener(getListener()))
                .desEncodeThenBuildAndSend();

    }

    /**
     * 老司机
     * @param uid
     * @param id
     */
    @Override
    public void onOldDriver(String uid, String id) {
        Type type = new TypeToken<HomeMallBean>() {
        }.getType();
//        String apiVer = api;
        Map<String, Object> map = new HashMap<>();
        map.put("uid", uid);
        map.put("id", id);

        (new ByJsonRequest.Builder<HomeMallBean>())
                .setTypeVerParamsAndReturnClass("", OldDriver, map, type)
                .requestListener(
                        new BaseSuccessReqListener<HomeMallBean>(
                                getListener()))
                .errorListener(new BaseErrorListener(getListener()))
                .desEncodeThenBuildAndSend();

    }

    @Override
    public void onRepair() {
        Type type = new TypeToken<WeiXiuBeans>() {
        }.getType();
        String apiVer = "100";
        Map<String, Object> map = new HashMap<>();

        (new ByJsonRequest.Builder<WeiXiuBeans>())
                .setTypeVerParamsAndReturnClass(ReTItle, apiVer, map, type)
                .requestListener(
                        new BaseSuccessReqListener<WeiXiuBeans>(
                                getListener()))
                .errorListener(new BaseErrorListener(getListener()))
                .desEncodeThenBuildAndSend();
    }
}
